package com.twu.biblioteca.service;

import com.twu.biblioteca.model.bookModel;
import com.twu.biblioteca.model.movieModel;
import com.twu.biblioteca.model.user;

import java.io.InputStream;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: st
 * Date: 14-4-17
 * Time: 下午2:27
 * To change this template use File | Settings | File Templates.
 */
public class menuOption {

    checkOutBook customerCheckOutBook=new checkOutBook();
    returnBook customerReturnBook = new returnBook();
    checkOutMovie customerCheckOutMovie = new checkOutMovie();
    returnMovie customerReturnMovie = new returnMovie();
    public String getInput(InputStream in)
    {
        Scanner sc = new Scanner(in);
        String option = sc.nextLine();
        return option;
    }

    public bookModel[] classifyOption(String optionNum,bookModel[] bookList,setup setupBook,InputStream in,movieModel movieList[],setupMovieList setupMovieList,int customerLen,user[] userList){

        if(optionNum.equals("1")){
            setupBook.printBookList(bookList);

            classifyOption(getInput(in),bookList,setupBook,in,movieList,setupMovieList,customerLen,userList);

        }
        if(optionNum.equals("2")){

            bookList= customerCheckOutBook.checkOut(bookList,customerCheckOutBook.checkBookInfo(in),customerLen,userList) ;

            classifyOption(getInput(in),bookList,setupBook,in,movieList,setupMovieList,customerLen,userList);
        }
        if(optionNum.equals("3")){

            bookList=customerReturnBook.return_book(bookList,customerReturnBook.returnBookInfo(in),customerLen,userList);

            classifyOption(getInput(in),bookList,setupBook,in,movieList,setupMovieList,customerLen,userList);
        }
        if(!optionNum.equals("1")&&!optionNum.equals("0") && !optionNum.equals("2")&&!optionNum.equals("3")
                &&!optionNum.equals("4")&&!optionNum.equals("5")&&!optionNum.equals("6")&&!optionNum.equals("7")){
            System.out.println("\n Select a valid option!");

            classifyOption(getInput(in),bookList,setupBook,in,movieList,setupMovieList,customerLen,userList);
        }
        if (optionNum.equals("4")){
            setupMovieList.printMovieList(movieList);
            classifyOption(getInput(in),bookList,setupBook,in,movieList,setupMovieList,customerLen,userList);
        }
        if(optionNum.equals("5")){
            movieList= customerCheckOutMovie.checkOut(movieList,customerCheckOutMovie.checkMovieInfo(in));
            classifyOption(getInput(in),bookList,setupBook,in,movieList,setupMovieList,customerLen,userList);
        }
        if(optionNum.equals("6")){
            movieList=customerReturnMovie.return_movie(movieList,customerReturnMovie.returnMovieInfo(in));
            classifyOption(getInput(in),bookList,setupBook,in,movieList,setupMovieList,customerLen,userList);
        }
        if(optionNum.equals("7")){
            setupUsers.printUserList(userList,customerLen);
            classifyOption(getInput(in),bookList,setupBook,in,movieList,setupMovieList,customerLen,userList);
        }
        if(optionNum.equals("0")){
            System.out.println("\n Quit the system.");
        }
     return bookList;
    }


}
